package com.yangye.pisystem.controller;

import com.yangye.picommon.model.PiResult;
import com.yangye.picommon.model.page.PageRequest;
import com.yangye.picommon.model.page.PageResult;
import com.yangye.pisystem.domain.SysDict;
import com.yangye.pisystem.service.SysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
* @author yangye
* @date 2020-3-18
* 自动生成代码
*/
@RestController
@RequestMapping("sys/dicts")
public class SysDictController {

    @Autowired
    private SysDictService sysDictService;

    /**
    * 新增
    * @param sysDict
    * @return
    */
    @PostMapping("/")
    @PreAuthorize("hasAuthority('sys:dict:add')")
    PiResult add(@RequestBody SysDict sysDict) {
        sysDictService.add(sysDict);
        return PiResult.succeed();
    }

    /**
    * 删除
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('sys:dict:remove')")
    PiResult remove(@PathVariable Long id) {
        sysDictService.remove(id);
        return PiResult.succeed();
    }

    /**
    * 修改
    * @param sysDict
    * @return
    */
    @PutMapping("/")
    @PreAuthorize("hasAuthority('sys:dict:update')")
    PiResult update(@RequestBody SysDict sysDict) {
        sysDictService.update(sysDict);
        return PiResult.succeed();
    }

    /**
    * 查看详情
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('sys:dict:view')")
    PiResult get(@PathVariable Long id) {
        SysDict sysDict = sysDictService.get(id);
        return PiResult.succeed(sysDict);
    }

    /**
    * 查看分页
    * @param sysDict
    * @param pageRequest
    * @return
    */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('sys:dict')")
    PiResult listPage(SysDict sysDict, PageRequest pageRequest) {
    PageResult<SysDict> page = sysDictService.findPage(sysDict, pageRequest);
        return PiResult.succeed(page);
    }
}